package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.GodBean;
import nero.yncc.com.createart.interfaces.InterfaceDoSomeThing;

/**
 * Created by nero on 17-6-27.
 */

public class AdapterDetailInandIn extends RecyclerView.Adapter<AdapterDetailInandIn.Holder>{

    Context context;
    ArrayList<GodBean.SpecAttrIn> arrayList;
    InterfaceDoSomeThing interfaceDoSomeThingNoArg;

    public AdapterDetailInandIn(Context context, ArrayList<GodBean.SpecAttrIn> arrayList ,InterfaceDoSomeThing interfaceDoSomeThingNoArg) {
        this.context = context;
        this.arrayList = arrayList;
        this.interfaceDoSomeThingNoArg=interfaceDoSomeThingNoArg;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.adapter_guige,null,false);
//        View view= LinearLayout.inflate(context,R.layout.adapter_guige,null);
        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        GodBean.SpecAttrIn bean=arrayList.get(position);
        holder.tv_content.setText(bean.getItem());
        if(bean.isChoose()){
            holder.tv_content.setTextColor(context.getResources().getColor(R.color.project_red_low)) ;
            holder.tv_content.setBackgroundResource(R.drawable.border_red_deep_arc_noround);
        }else{
            holder.tv_content.setTextColor(context.getResources().getColor(R.color.textColorGray)) ;
            holder.tv_content.setBackgroundResource(R.drawable.border_gray_deep_arc_noround);
        }

        holder.tv_content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for ( GodBean.SpecAttrIn bean_cache: arrayList){
                    bean_cache.setChoose(false);
                }
                arrayList.get(position).setChoose(true);
                AdapterDetailInandIn.this.notifyDataSetChanged();
                interfaceDoSomeThingNoArg.doSomething(    arrayList.get(position).getItem_id());
            }
        });
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    class Holder extends RecyclerView.ViewHolder{
        TextView tv_content;
        public Holder(View itemView) {
            super(itemView);
            tv_content=itemView.findViewById(R.id.tv_content);
        }
    }
}
